/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.CES.businessLogic;

import com.bionic.CES.DAO.IBankaccDAO;
import com.bionic.CES.beans.Bankacc;
import com.bionic.CES.connections.DAOFactory;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author Jarik
 */
public class BankAccService {

    public static IBankaccDAO bankaccDAO;

    static {
        DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
        bankaccDAO = factory.getBankaccDAO();
    }

    public static void createNewBankacc(Integer accNum, String currency, String bankName,
            String swift, String correspondentBank, Integer userId) {
        Bankacc bankacc = new Bankacc();
        bankacc.setAccNum(accNum);
        bankacc.setCurrency(currency);
        bankacc.setBankName(bankName);
        bankacc.setSwift(swift);
        bankacc.setCorrespondentBank(correspondentBank);
        bankacc.setUserId(userId);

        try {
            bankaccDAO.add(bankacc);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static void updateCurrentBankacc(Integer accNum, String currency, String bankName,
            String swift, String correspondentBank) {
        Bankacc bankacc = new Bankacc();
        bankacc.setAccNum(accNum);
        bankacc.setCurrency(currency);
        bankacc.setBankName(bankName);
        bankacc.setSwift(swift);
        bankacc.setCorrespondentBank(correspondentBank);
        try {
            bankaccDAO.update(bankacc);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static void deleteCurrentBankacc(Integer bankaccId) {
        try {
            bankaccDAO.deleteById(bankaccId);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static List<Bankacc> returnCurrentBankaccInfo(Integer userId) {
        List<Bankacc> list = null;
        Bankacc bankacc = new Bankacc();
        bankacc.setUserId(userId);
        try {
            list = bankaccDAO.findByDynamicSelect(bankacc);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return list;
    }

}
